import gtk
import bonobo
import bonobo.ui

import gnome
import gnome.ui

prog = gnome.program_init('foo', 'blah')


w = bonobo.ui.Window('name', 'title')
s = 'OAFIID:GNOME_GtkHTML_Editor:3.8'
c = bonobo.ui.Widget(s, w.get_ui_container().corba_objref())

c.show_all()
w.set_contents(c)
w.show_all()

print dir(c.get_objref())
p = c.get_objref().getProperties()
print dir(p)
print p.getKeys('')
#print p.setValue('FormatHTML', 1)
bonobo.pbclient_set_boolean(p, 'FormatHTML', True)

ppi = bonobo.Application('ass')
print dir(ppi)

#.set_property('formatHTML', True)

"""
<oaf_attribute name="repo_ids" type="stringv">
                <item value="IDL:Bonobo/Control:1.0"/>
                <item value="IDL:Bonobo/Unknown:1.0"/>
                <item value="IDL:Bonobo/PersistStream:1.0"/>
                <item value="IDL:Bonobo/PersistFile:1.0"/>
                <item value="IDL:Bonobo/Persist:1.0"/>
        </oaf_attribute>
        <item value="IDL:GNOME/GenericFactory:1.0"/>
"""

ints = [
                "IDL:Bonobo/Control:1.0",
                "IDL:Bonobo/Unknown:1.0",
                "IDL:Bonobo/PersistStream:1.0",
                "IDL:Bonobo/PersistFile:1.0",
                "IDL:Bonobo/Persist:1.0",
                "IDL:GNOME/GenericFactory:1.0"]

o = c.get_objref().queryInterface('IDL:GNOME/GtkHTML/Editor/Engine:1.0')

o.insertHTML('<PRE>\nhello\n</PRE>')

print o.runCommand('undo')
print o.runCommand('redo')
print o.getParagraphData('1')
print o.isParagraphEmpty()
print dir(o)

i = c.get_objref().queryInterface('IDL:Bonobo/PersistStream:1.0')
print dir(i)
print i.getContentTypes()

#fn = '/home/ali/.local/share/Trash/files/OLAT/olat/webapp/static/help/de/ced-wiki.html'

#dat = open(fn).read()

dat = """
<html>
<body>
hello
<pre>
this is
pre
formatted
text
<pre>
</body>
</html>
"""

st = bonobo.StreamMem(dat, True, False)
i.load(st.corba_objref(), 'text/html')

def save():
# second argument must be False (read-only)
    st = bonobo.StreamMem('', False, True)
    i.save(st.corba_objref(), 'text/html')
    print bonobo.stream_client_read(st.corba_objref())
    print st.get_buffer()
    return True

import gobject
gobject.timeout_add(3000, save)
gtk.main()

